package bstsetcode.stanforduniversity18;

/**
 * @author noob
 * @version 1.0
 * @date 2021/3/15 20:19
 * 插入排序
 */
public class InsertionSorted {


    public static <E extends Comparable<E>>  void sorted(E[] data){
        for (int i = 0; i < data.length; i++) {
            E value = data[i];
            int j;
            for ( j = i;  j -1>= 0 && value.compareTo(data[j-1])<0 ; j--) {
                data[j] = data[j-1];
            }
            data[j] = value ;
        }
    }

    public static void main(String[] args) {
        Integer[] arr = {1,8,7,4,5,6,4};
        InsertionSorted.sorted(arr);
        for(int n : arr){
            System.out.print(n+" ");
        }
    }
}
